package com.jilian.mydemo.modul.user.viewmodel;

import android.arch.lifecycle.LiveData;

import com.alibaba.fastjson.JSONObject;
import com.jilian.mydemo.base.BaseDto;
import com.jilian.mydemo.base.BaseViewModel;
import com.jilian.mydemo.base.BaseVo;
import com.jilian.mydemo.common.dto.BannerListDto;
import com.jilian.mydemo.common.dto.CommiteDto;
import com.jilian.mydemo.common.dto.GoodsTypeDto;
import com.jilian.mydemo.common.dto.LeaveStatusDto;
import com.jilian.mydemo.common.dto.PartnerDescriptionDto;
import com.jilian.mydemo.common.dto.ProductDetailDto;
import com.jilian.mydemo.common.dto.ProductListDto;
import com.jilian.mydemo.common.dto.QuestionDto;
import com.jilian.mydemo.common.dto.StudyListDto;
import com.jilian.mydemo.common.dto.VideoArticlesDto;
import com.jilian.mydemo.common.dto.VideoArticlesListDto;
import com.jilian.mydemo.common.dto.LoginDto;
import com.jilian.mydemo.common.dto.MyInfoDto;
import com.jilian.mydemo.common.dto.WrongAnwserDto;
import com.jilian.mydemo.common.vo.AppUserInfoVO;
import com.jilian.mydemo.common.vo.ArticleDetailVo;
import com.jilian.mydemo.common.vo.BannerVo;
import com.jilian.mydemo.common.vo.BrowseArticleVO;
import com.jilian.mydemo.common.vo.CollectVo;
import com.jilian.mydemo.common.vo.ComminteListVo;
import com.jilian.mydemo.common.vo.GoodDetailVo;
import com.jilian.mydemo.common.vo.LeaveVo;
import com.jilian.mydemo.common.vo.PartnerApplyVo;
import com.jilian.mydemo.common.vo.PhotoVerifyVo;
import com.jilian.mydemo.common.vo.ProductListVo;
import com.jilian.mydemo.common.vo.SendSmsVo;
import com.jilian.mydemo.common.vo.LoginVo;
import com.jilian.mydemo.common.vo.ServiceAreaVo;
import com.jilian.mydemo.common.vo.ServiceAreasStrVo;
import com.jilian.mydemo.common.vo.UpdatePasswordVo;
import com.jilian.mydemo.common.vo.UserRegistVo;
import com.jilian.mydemo.factory.Factoty;
import com.jilian.mydemo.modul.user.repository.UserRepository;

import java.io.File;
import java.util.List;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 用户相关 viewmodel
 */
@Data
@EqualsAndHashCode(callSuper = false)
public class UserViewModel extends BaseViewModel {
    /**
     * 登陆
     */
    private LiveData<BaseDto<LoginDto>> loginliveData;

    /**
     * 获取验证码
     */
    private LiveData<BaseDto> smsliveData;

    /**
     * 注册
     */
    private LiveData<BaseDto> registliveData;

    /**
     * 实名认证卡口，根据返回状态进行跳转
     */
    private LiveData<BaseDto<Integer>> checkliveData;

    /**
     * 个人信息
     */
    private LiveData<BaseDto<MyInfoDto>> infoliveData;

    /**
     * 修改密码
     */
    private LiveData<BaseDto> updatePwdliveData;

    /**
     * 修改手机号
     */
    private LiveData<BaseDto> updatePhoneliveData;

    /**
     * 用户信息
     */
    private LiveData<BaseDto> updateUserliveData;
    /**
     * 实名认证
     */
    private LiveData<BaseDto> photoVerifyliveData;

    /**
     * 我的收藏
     */
    private LiveData<BaseDto<VideoArticlesListDto>> collectListliveData;

    /**
     * 水工课堂列表
     */
    private LiveData<BaseDto<VideoArticlesListDto>> videoArticlesliveData;
    /**
     * 文章详情
     */
    private LiveData<BaseDto<VideoArticlesDto>> articlesDetailliveData;

    /**
     * 配件商城
     */
    private LiveData<BaseDto<ProductListDto>> productliveData;
    /**
     * 获取商品类型
     */
    private LiveData<BaseDto<List<GoodsTypeDto>>> goodsTypeDtoliveData;

    /**
     * 收藏
     */
    private LiveData<BaseDto> collectliveData;

    /**
     * 商品详情
     */
    private LiveData<BaseDto<ProductDetailDto>> detailliveData;

    /**
     * 随机20道题
     *
     * @param
     * @return
     */
    private LiveData<BaseDto<List<QuestionDto>>> questionliveData;

    /**
     * 学习手册
     */
    private LiveData<BaseDto<StudyListDto>> studyliveData;
    /**
     * 提交答案
     */
    private LiveData<BaseDto<CommiteDto>> submitliveData;
    /**
     * 查看错题
     */
    private LiveData<BaseDto<List<WrongAnwserDto>>> wrongliveData;

    /**
     * 重置密码
     */
    private LiveData<BaseDto> updateliveData;

    /**
     * 获取百万合作说明
     */
    private LiveData<BaseDto<PartnerDescriptionDto>> partnerDescriptionliveData;
    /**
     * 合伙人申请
     */
    private LiveData<BaseDto> partnerApplyliveData;

    /**
     * 获取合伙人申请状态
     */
    private LiveData<BaseDto<PartnerDescriptionDto>> applyStatusliveData;
    /**
     * 点击去接单掉该接口
     */
    private LiveData<BaseDto> clickedliveData;

    /**
     * 获取请假状态
     */
    private LiveData<BaseDto<LeaveStatusDto>> leaveStatusliveData;
    /**
     * 请假
     */
    private LiveData<BaseDto> leaveliveData;

    /**
     * 接单
     */
    private LiveData<BaseDto> takeOrderLiveData;
    /**
     * 广告图片
     */
    private LiveData<BaseDto<BannerListDto>> bannerLiveData;

    public LiveData<BaseDto<LoginDto>> getLoginliveData() {
        return loginliveData;
    }

    public LiveData<BaseDto> getSmsliveData() {
        return smsliveData;
    }

    public LiveData<BaseDto> getRegistliveData() {
        return registliveData;
    }

    public LiveData<BaseDto<Integer>> getCheckliveData() {
        return checkliveData;
    }

    public LiveData<BaseDto<MyInfoDto>> getInfoliveData() {
        return infoliveData;
    }

    public LiveData<BaseDto> getUpdatePwdliveData() {
        return updatePwdliveData;
    }

    public LiveData<BaseDto> getUpdatePhoneliveData() {
        return updatePhoneliveData;
    }

    public LiveData<BaseDto> getUpdateUserliveData() {
        return updateUserliveData;
    }

    public LiveData<BaseDto> getPhotoVerifyliveData() {
        return photoVerifyliveData;
    }

    public LiveData<BaseDto<VideoArticlesListDto>> getCollectListliveData() {
        return collectListliveData;
    }

    public LiveData<BaseDto<VideoArticlesListDto>> getVideoArticlesliveData() {
        return videoArticlesliveData;
    }

    public LiveData<BaseDto<VideoArticlesDto>> getArticlesDetailliveData() {
        return articlesDetailliveData;
    }

    public LiveData<BaseDto<ProductListDto>> getProductliveData() {
        return productliveData;
    }

    public LiveData<BaseDto<List<GoodsTypeDto>>> getGoodsTypeDtoliveData() {
        return goodsTypeDtoliveData;
    }

    public LiveData<BaseDto> getCollectliveData() {
        return collectliveData;
    }

    public LiveData<BaseDto<ProductDetailDto>> getDetailliveData() {
        return detailliveData;
    }

    public LiveData<BaseDto<List<QuestionDto>>> getQuestionliveData() {
        return questionliveData;
    }

    public LiveData<BaseDto<StudyListDto>> getStudyliveData() {
        return studyliveData;
    }

    public LiveData<BaseDto<CommiteDto>> getSubmitliveData() {
        return submitliveData;
    }

    public LiveData<BaseDto<List<WrongAnwserDto>>> getWrongliveData() {
        return wrongliveData;
    }

    public LiveData<BaseDto> getUpdateliveData() {
        return updateliveData;
    }

    public LiveData<BaseDto<PartnerDescriptionDto>> getPartnerDescriptionliveData() {
        return partnerDescriptionliveData;
    }

    public LiveData<BaseDto> getPartnerApplyliveData() {
        return partnerApplyliveData;
    }

    public LiveData<BaseDto<PartnerDescriptionDto>> getApplyStatusliveData() {
        return applyStatusliveData;
    }

    public LiveData<BaseDto> getClickedliveData() {
        return clickedliveData;
    }

    public LiveData<BaseDto<LeaveStatusDto>> getLeaveStatusliveData() {
        return leaveStatusliveData;
    }

    public LiveData<BaseDto> getLeaveliveData() {
        return leaveliveData;
    }

    public LiveData<BaseDto> getTakeOrderLiveData() {
        return takeOrderLiveData;
    }

    public LiveData<BaseDto<BannerListDto>> getBannerLiveData() {
        return bannerLiveData;
    }

    /**
     * 登录
     *
     * @param phone
     * @param pwd
     */
    public void login(String phone, String pwd, String location) {
        LoginVo vo = new LoginVo();
        vo.setPassword(pwd);
        vo.setPhone(phone);
        vo.setLocation(location);
        loginliveData = Factoty.getRepository(UserRepository.class).login(vo);
    }

    /**
     * 获取验证码
     *
     * @param phone
     * @param type
     */
    public void sendSms(String phone, int type) {
        SendSmsVo vo = new SendSmsVo(phone, type);
        smsliveData = Factoty.getRepository(UserRepository.class).sendSms(vo);
    }

    /**
     * @param location
     * @param password
     * @param phone
     * @param validCode
     */
    public void regist(String location, String password, String phone, String validCode) {
        UserRegistVo vo = new UserRegistVo();
        vo.setLocation(location);
        vo.setPassword(password);
        vo.setPhone(phone);
        vo.setValidCode(validCode);
        registliveData = Factoty.getRepository(UserRepository.class).regist(vo);
    }

    /**
     * 实名认证卡口，根据返回状态进行跳转
     */
    public void check() {
        checkliveData = Factoty.getRepository(UserRepository.class).check();
    }

    /**
     * 个人信息接口
     */
    public void info() {
        infoliveData = Factoty.getRepository(UserRepository.class).info();
    }

    /**
     * 修改密码
     *
     * @param oldPassword
     */
    public void updateUserPassword(String oldPassword, String password) {
        AppUserInfoVO vo = new AppUserInfoVO();
        vo.setOldPassword(oldPassword);
        vo.setPassword(password);
        updatePwdliveData = Factoty.getRepository(UserRepository.class).updateUserPassword(vo);
    }

    /**
     * 修改手机号
     *
     * @param userPhone
     * @param validCode
     */
    public void updateUserPhone(String userPhone, String validCode) {
        AppUserInfoVO vo = new AppUserInfoVO();
        vo.setUserPhone(userPhone);
        vo.setValidCode(validCode);
        updatePhoneliveData = Factoty.getRepository(UserRepository.class).updateUserPhone(vo);
    }


    /**
     * 修改用户信息
     *
     * @param voList
     * @param fileList
     * @return
     */
    public void updateUserInfo(List<ServiceAreaVo> voList, String area, String contactAddress,String skill,List<File> fileList) {
        ServiceAreasStrVo vo = new ServiceAreasStrVo();
        vo.setServiceAreas(JSONObject.toJSONString(voList));
        vo.setArea(area);
        vo.setContactAddress(contactAddress);
        vo.setSkill(skill);
        updateUserliveData = Factoty.getRepository(UserRepository.class).updateUserInfo(vo, fileList);
    }


    /**
     * 我的收藏
     *
     * @param pageNum
     * @param pageSize
     */
    public void queryCollect(Integer pageNum, Integer pageSize) {
        BaseVo vo = new BaseVo();
        vo.setPageNum(pageNum);
        vo.setPageSize(pageSize);
        collectListliveData = Factoty.getRepository(UserRepository.class).queryCollect(vo);
    }

    /**
     * 水工课堂列表
     *
     * @param pageNum
     * @param pageSize
     */
    public void queryArticle(Integer pageNum, Integer pageSize) {
        BaseVo vo = new BaseVo();
        vo.setPageNum(pageNum);
        vo.setPageSize(pageSize);
        videoArticlesliveData = Factoty.getRepository(UserRepository.class).queryArticle(vo);
    }

    public void queryAppArticleDetail(String id) {
        ArticleDetailVo vo = new ArticleDetailVo();
        vo.setArticleId(id);
        articlesDetailliveData = Factoty.getRepository(UserRepository.class).queryAppArticleDetail(vo);
    }


    /**
     * 配件商城
     *
     * @param pageNum
     * @param pageSize
     * @param productName 商品名称
     * @param productType 商品类型
     */
    public void getAppProductList(Integer pageNum, Integer pageSize, String productName, String productType) {
        ProductListVo vo = new ProductListVo();
        vo.setPageNum(pageNum);
        vo.setPageSize(pageSize);
        vo.setProductName(productName);
        vo.setProductType(productType);
        productliveData = Factoty.getRepository(UserRepository.class).getAppProductList(vo);
    }

    /**
     * 获取商品类型
     */
    public void queryProductTypes() {
        goodsTypeDtoliveData = Factoty.getRepository(UserRepository.class).queryProductTypes();
    }


    /**
     * 收藏
     * 收藏ID
     *
     * @param articleId
     */
    public void addCollect(Long articleId, Integer isCollect) {
        BrowseArticleVO vo = new BrowseArticleVO();
        vo.setArticleId(articleId);
        vo.setIsCollect(isCollect);
        collectliveData = Factoty.getRepository(UserRepository.class).addCollect(vo);
    }

    /**
     * 商品详情
     *
     * @param id 商品详情ID
     */
    public void getAppProductDetail(Long id) {
        GoodDetailVo vo = new GoodDetailVo();
        vo.setId(id);
        detailliveData = Factoty.getRepository(UserRepository.class).getAppProductDetail(vo);
    }

    /**
     * 随机20道题
     *
     * @param
     * @return
     */
    public void random() {
        questionliveData = Factoty.getRepository(UserRepository.class).random();
    }

    /**
     * 提交答案
     *
     * @param vo
     */
    public void submit(ComminteListVo vo) {
        submitliveData = Factoty.getRepository(UserRepository.class).submit(vo);
    }


    /**
     * 实名认证
     *
     * @param idcard
     * @param name
     * @param serviceAreas
     * @param frontImg
     * @param backImg
     */
    public void photoVerify(String idcard, String name, String serviceAreas,  String area, String contactAddress,String skill, List<File> frontImg, List<File> backImg) {
        PhotoVerifyVo vo = new PhotoVerifyVo();
        vo.setIdcard(idcard);
        vo.setName(name);
        vo.setServiceAreas(serviceAreas);
        vo.setArea(area);
        vo.setContactAddress(contactAddress);
        vo.setSkill(skill);
        photoVerifyliveData = Factoty.getRepository(UserRepository.class).photoVerify(vo, frontImg, backImg);
    }

    /**
     * 查看错题
     */
    public void wrong() {
        wrongliveData = Factoty.getRepository(UserRepository.class).wrong();
    }


    /**
     * 学习手册
     */
    public void study() {
        studyliveData = Factoty.getRepository(UserRepository.class).study();
    }


    /**
     * 重置密码
     *
     * @param password
     * @param phone
     * @param validCode
     */
    public void updatePassword(String phone, String validCode, String password) {
        UpdatePasswordVo vo = new UpdatePasswordVo();
        vo.setPassword(password);
        vo.setPhone(phone);
        vo.setValidCode(validCode);
        updateliveData = Factoty.getRepository(UserRepository.class).updatePassword(vo);
    }

    /**
     * 获取百万合伙人说明
     */
    public void getPartnerDescription() {
        partnerDescriptionliveData = Factoty.getRepository(UserRepository.class).getPartnerDescription();
    }

    /**
     * @param age
     * @param partnerName
     * @param phone
     * @param storeAddress
     * @param storeSize
     * @param workYears
     * @param businessLicense
     * @param storeLogo
     */
    public void partnerApply(String age, String partnerName, String phone, String storeAddress, String storeSize, String workYears, String area, List<File> businessLicense, List<File> storeLogo) {
        PartnerApplyVo vo = new PartnerApplyVo();
        vo.setAge(age);
        vo.setPartnerName(partnerName);
        vo.setPhone(phone);
        vo.setStoreAddress(storeAddress);
        vo.setStoreSize(storeSize);
        vo.setWorkYears(workYears);
        vo.setServiceArea(area);
        partnerApplyliveData = Factoty.getRepository(UserRepository.class).partnerApply(vo, businessLicense, storeLogo);
    }

    /**
     * 获取合伙人申请状态
     *
     * @return
     */
    public void getPartnerApply() {
        applyStatusliveData = Factoty.getRepository(UserRepository.class).getPartnerApply();
    }

    /**
     * 点击去接单掉该接口
     *
     * @return
     */
    public void clicked() {
        clickedliveData = Factoty.getRepository(UserRepository.class).clicked();
    }

    /**
     * 获取请假状态
     *
     * @return
     */
    public void getLeaveStatus() {
        leaveStatusliveData = Factoty.getRepository(UserRepository.class).getLeaveStatus();

    }

    /**
     * 取消接单 请假
     *
     * @return
     */
    public void leave(LeaveVo vo) {
        leaveliveData = Factoty.getRepository(UserRepository.class).leave(vo);

    }

    /**
     * 接单
     *
     * @return
     */
    public void takeOrder() {
        takeOrderLiveData = Factoty.getRepository(UserRepository.class).takeOrder();

    }


    public void getAppAdList(BannerVo vo) {
        bannerLiveData = Factoty.getRepository(UserRepository.class).getAppAdList(vo);

    }
}
